<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<!-- Content Header (Page header) -->
<section class="content-header">
	<h1>
		<c:choose>
			<c:when test="${mode=='view'}">
				<spring:message code="admin.product.group.view" />
			</c:when>
			<c:when test="${mode=='edit'}">
				<spring:message code="admin.product.group.update" />
			</c:when>
			<c:otherwise>
				<spring:message code="admin.product.group.new" />
			</c:otherwise>
		</c:choose>
	</h1>
	<ol class="breadcrumb">
		<li><a href="goHomePage.html"><i class="fa fa-dashboard"></i> <spring:message code="admin.homepage.title" /></a></li>
		<li class="active"><spring:message code="admin.product.group.title" /></li>
	</ol>
</section>

<!-- Main content -->
<section class="content">
	<div class="row">
		<!-- left column -->
		<div class="col-md-12">
			<!-- general form elements -->
			<div class="box box-primary">
				<div class="box-header">
					<h3 class="box-title">
						<c:choose>
							<c:when test="${mode=='view'}">
								<spring:message code="admin.product.group.view" />
							</c:when>
							<c:when test="${mode=='edit'}">
								<spring:message code="admin.product.group.update" />
							</c:when>
							<c:otherwise>
								<spring:message code="admin.product.group.new" />
							</c:otherwise>
						</c:choose>
					</h3>
				</div>
				<!-- /.box-header -->
				<!-- form start -->
				<form:form role="form" action="saveProductGroup.html" method="post" commandName="productGroup" onsubmit="return validateForm();">
					<form:hidden path="id" />
					<div class="box-body">
						<div class="form-group">
							<label><spring:message code="admin.product.group.name" /></label>
							<form:input type="text" placeholder="" class="form-control" path="name" />
						</div>
						<div class="form-group">
							<label><spring:message code="admin.product.group.keyword" /></label>
							<form:input type="text" placeholder="" class="form-control" path="keyword" />
						</div>
						<div class="form-group">
							<label><spring:message code="admin.product.group.status" /></label>
							<div class="checkbox">
								<label class="">
									<div class="icheckbox_minimal" style="position: relative;" aria-checked="false" aria-disabled="false">
										<form:checkbox style="position: absolute; opacity: 0;" path="status" value="1" />
										<ins class="iCheck-helper"
											style="position: absolute; top: 0%; left: 0%; display: block; width: 100%; height: 100%; margin: 0px; padding: 0px; background: none repeat scroll 0% 0% rgb(255, 255, 255); border: 0px none; opacity: 0;"></ins>
									</div> <spring:message code="admin.product.group.active" />
								</label>
							</div>
						</div>
						<div class="form-group">
							<label> <spring:message code="admin.product.group.description" /></label>
							<form:textarea placeholder="" rows="3" class="form-control" path="description"></form:textarea>
						</div>

						<div class="form-group">
							<label> <spring:message code="admin.product.group.parent.group" /></label>
							<form:select class="form-control" path="parentProductGroupList[0].id">
								<form:option value="">
									<spring:message code="admin.product.group.none" />
								</form:option>
								<c:forEach items="${parentPG }" var="pg">
									<form:option value="${pg.id }">
										<c:out value='${pg.name }' />
									</form:option>
								</c:forEach>
							</form:select>
						</div>
					</div>
					<!-- /.box-body -->
					<c:if test="${mode !='view' }">
						<div class="box-footer">
							<button class="btn btn-success" type="submit">
								<spring:message code="admin.form.button.submit" />
							</button>
							<c:choose>
								<c:when test="${mode == 'edit' }">
									<button class="btn btn-primary" type="button" onclick="history.back(1);">
										<spring:message code="admin.form.button.back" />
									</button>
								</c:when>
								<c:otherwise>
									<button class="btn btn-warning" type="reset">
										<spring:message code="admin.form.button.reset" />
									</button>
								</c:otherwise>
							</c:choose>
						</div>
					</c:if>
				</form:form>
				<c:if test="${mode =='view' }">
					<form:form>
						<div class="box-footer">
							<button class="btn btn-success" type="button" onclick="updateProductGroup(${productGroup.id})">
								<spring:message code="admin.form.button.edit" />
							</button>
							<button class="btn btn-primary" type="button" onclick="history.back(1);">
								<spring:message code="admin.form.button.back" />
							</button>
						</div>
					</form:form>
				</c:if>
			</div>
			<!-- /.box -->
		</div>
		<!--/.col (right) -->
	</div>
	<!-- /.row -->
</section>
<!-- /.content -->
<script type="text/javascript">
	$(function() {
		if ('${mode}' == "view") {
			$("#productGroup :input").attr('disabled', true);
		}
	});
	
	function updateProductGroup(id) {
		window.location.href='updateProductGroup.html?id='+id;
	}
	
	function validateForm() {
		if ($('#name').val().trim().length==0) {
			$('#name').css('border-color','red');
			return false;
		} else {
			$('#name').css('border-color','');
		}
		
		if ($('#keyword').val().trim().length==0) {
			$('#keyword').css('border-color','red');
			return false;
		} else {
			$('#keyword').css('border-color','');
		}
		
		if ($('#description').val().trim().length==0) {
			$('#description').css('border-color','red');
			return false;
		} else {
			$('#description').css('border-color','');
		}
	}
</script>
